package org.jma.app.ewisdom.services.utils;

import org.jma.app.ewisdom.entities.FileDescriptor;
import org.jma.lib.utils.http.FileDownloader;

/**
 * EwisdomDownloader class creates a new thread that downloads a File from an url
 * TODO enable client authentication using certificates, by now all the files will be exposed by the server 
 * without client authentication and using http protocol... 
 * @author jesmari@ono.com
 * @version 1.0
 * @since 1.0
 */
public class EwisdomDownloader extends FileDownloader implements Runnable{
	FileDescriptor fd;
	Thread t;
	
	/**
	 * EwisdomDownloader constructor.
	 * @see FileDownloadedEvent
	 * @param fd the File descriptor, it is used to return the reference of a filedescriptor inside the FileDownloadedEvent 
	 * @param repository folder where it will save the file.
	 * @param fileName Usually a FilePart name.
	 * @param urlString the url to download
	 */
	public EwisdomDownloader(FileDescriptor fd,String repository,String fileName,String urlString){
		super(repository,fileName,urlString);
		super.setName(fd.hashCode()+"");
		this.fd=fd;
		t=new Thread(this);
	}
	/**
	 * gets the fileDescriptor
	 * @return a FileDescriptor
	 */
	public FileDescriptor getFileDescriptor(){
		return fd;
	}
	
	/**
	 * starts downloading
	 */
	public void start(){
		t.start(); // Start the child process
	}
}
